package br.com.pheat.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.pheat.beans.Usuario;
import br.com.pheat.dao.RefeicaoDAO;

public class RelatorioDiaSemanaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public RelatorioDiaSemanaServlet() {
        super();
    }

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		Usuario usuario = (Usuario) session.getAttribute("UsuarioLogado");
		try {
			String registros = RefeicaoDAO.getConsumoPorDiaSemana(usuario.getCodigo());

			request.setAttribute("dias", registros);
			RequestDispatcher dispatcher = request.getRequestDispatcher("dadoCaloriaSemana.jsp");
			dispatcher.forward(request, response);

		}catch(Exception e){
			response.sendRedirect("erro.jsp");
		}
	}
}
